package com.bbs.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bbs.resp.Result;
import com.bbs.resp.ResultMsg;
import com.bbs.service.ArticlesService;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
public class ArticlesServiceImpl implements ArticlesService {

    @Resource
    RestTemplate restTemplate;

    @Override
    public ResultMsg findByArticleId(String articleId) {
        return null;
    }

    @Override
    public ResultMsg findByUserId(String userId) {
        return null;
    }

    @Override
    public Result findByLike(String str) {
        String forObject = restTemplate.getForObject("http://172.16.1.2:9200/articles/_search?q=" + str, String.class);
        JSONObject jsonObject = JSON.parseObject(forObject);
        Object hits = jsonObject.getObject("hits", Object.class);
        return Result.of(true, HttpStatus.OK,hits);
    }

    @Override
    public ResultMsg deleteByArticleId(String articleId) {
        return null;
    }

    @Override
    public ResultMsg deleteByArticleIdList(String[] articles) {
        return null;
    }
}
